﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;

namespace FGCPDQ
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();

            #region CopyContentToIsolatedStorage

            Common.CopyContentToIsolatedStorage("assets/classlist.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_178.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_179.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_180.txt");
            Common.CopyContentToIsolatedStorage("assets/newslist_181.txt");

            Common.CopyContentToIsolatedStorage("html/695.html");
            Common.CopyContentToIsolatedStorage("html/696.html");
            Common.CopyContentToIsolatedStorage("html/697.html");
            Common.CopyContentToIsolatedStorage("html/698.html");
            Common.CopyContentToIsolatedStorage("html/699.html");
            Common.CopyContentToIsolatedStorage("html/700.html");
            Common.CopyContentToIsolatedStorage("html/701.html");
            Common.CopyContentToIsolatedStorage("html/702.html");
            Common.CopyContentToIsolatedStorage("html/703.html");
            Common.CopyContentToIsolatedStorage("html/704.html");
            Common.CopyContentToIsolatedStorage("html/705.html");
            Common.CopyContentToIsolatedStorage("html/706.html");
            Common.CopyContentToIsolatedStorage("html/707.html");
            Common.CopyContentToIsolatedStorage("html/708.html");
            Common.CopyContentToIsolatedStorage("html/709.html");
            Common.CopyContentToIsolatedStorage("html/710.html");
            Common.CopyContentToIsolatedStorage("html/711.html");
            Common.CopyContentToIsolatedStorage("html/712.html");
            Common.CopyContentToIsolatedStorage("html/713.html");
            Common.CopyContentToIsolatedStorage("html/714.html");
            Common.CopyContentToIsolatedStorage("html/715.html");
            Common.CopyContentToIsolatedStorage("html/716.html");
            Common.CopyContentToIsolatedStorage("html/717.html");
            Common.CopyContentToIsolatedStorage("html/718.html");
            Common.CopyContentToIsolatedStorage("html/719.html");
            Common.CopyContentToIsolatedStorage("html/720.html");
            Common.CopyContentToIsolatedStorage("html/721.html");
            Common.CopyContentToIsolatedStorage("html/722.html");
            Common.CopyContentToIsolatedStorage("html/723.html");
            Common.CopyContentToIsolatedStorage("html/724.html");
            Common.CopyContentToIsolatedStorage("html/725.html");
            Common.CopyContentToIsolatedStorage("html/public.css");

            Common.CopyContentToIsolatedStorage("img/sec.png");
            Common.CopyContentToIsolatedStorage("img/20120425100403_1306847549.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100416_1414547927.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100419_1862196660.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100420_2057090781.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100420_75442180.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100422_1147437726.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100422_2021852178.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100423_979776857.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100432_1182708597.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100433_164186691.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100440_2007140346.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425100444_661863717.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110401_1214899641.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110409_767224704.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110413_77246832.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110420_1103487518.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110420_698963970.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110425_1742608684.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110430_1091183540.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110434_1744177660.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110435_1123916951.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110439_873856364.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110441_917497943.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110444_1077685536.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425110451_1959735975.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130408_1344276823.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130408_1505326331.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130411_395236853.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130429_1127326041.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130435_253097517.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130440_699165952.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130446_587583576.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130447_662778808.jpg");
            Common.CopyContentToIsolatedStorage("img/20120425130456_1035389546.jpg");

            #endregion
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string jsonClassList = "";
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (myIsolatedStorage.FileExists("assets/classlist.txt"))
                {
                    using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("assets/classlist.txt", FileMode.Open, FileAccess.Read))
                    {
                        if (stream.Length > 0)
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                jsonClassList = reader.ReadLine();
                            }
                        }
                    }
                }
            }
            if (!String.IsNullOrEmpty(jsonClassList))
            {
                List<ClassList> listclass = JsonHelper.Deserialize<List<ClassList>>(jsonClassList);
                pList.ItemsSource = listclass;
            }
        }

        private void pList_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri(String.Format("/DetailList.xaml?c={0}", (pList.SelectedValue as ClassList).id), UriKind.Relative));
        }
    }
}